#include<stdio.h>
#include<stdint.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/timerfd.h>
#include<time.h>
int main()
{
    int tfd = timerfd_create(CLOCK_MONOTONIC,0);//阻塞式定时器
    if(tfd == -1){
        perror("timerfd_create error");
        return -1;
    }
    struct itimerspec its;
    its.it_value.tv_sec = 1;//第一次到期时间为1s后
    its.it_value.tv_nsec = 0;
    its.it_interval.tv_sec = 3;//间隔时间为3s
    its.it_interval.tv_nsec = 0;
    int ret = timerfd_settime(tfd,0,&its,NULL);
    if(ret == -1){
        perror("timerfd_settime error");
        close(tfd);
        return -1;
    }
    while(1){
        
        uint64_t exp;
        int n = read(tfd,&exp,8);
        if(n<0){
            perror("read error");
            close(tfd);
            return -1;
        }
        
        printf("超时： %ld\n",exp);

    }
    close(tfd);
    return 0;
}

